//Accepted
//http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=614
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main (){
	//freopen("in.txt", "r", stdin);
	string s;
	int t, i, n;
	
	scanf("%d\n", &t);
	while(t--){
		getline(cin,s);
		n=s.size();
		for(i=0;i<n-1;){
			if( ((s[i] == '(') && (s[i+1] == ')')) || ((s[i]=='[') && (s[i+1]==']')) ){
				s.erase(i,2);
				--i;
				if(i<0)++i;
				n-=2;
			}
			else{
				++i;
			}
		}
		if(n>0)printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}